package com.shop.web;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.file.CopyOption;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;

import org.apache.commons.io.IOUtils;
import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;

public class UploadAction extends ActionSupport {
	private File upload;
	private String uploadContentType;
	private String uploadFileName;
	
	@Override
	public String execute() throws Exception {
		String path=ServletActionContext.getServletContext().getRealPath("uploadFiles");
		FileInputStream input = new FileInputStream(upload);
		//File uploadFile = new File(path,uploadFileName);
		//FileOutputStream output = new FileOutputStream(uploadFile);
		//IOUtils.copy(input, output );
		//上传的目标文件
		Path target = Paths.get(path,uploadFileName );
		Files.copy(input, target, StandardCopyOption.REPLACE_EXISTING);
		return super.execute();
	}
	
	public File getUpload() {
		return upload;
	}
	public void setUpload(File upload) {
		this.upload = upload;
	}
	public String getUploadContentType() {
		return uploadContentType;
	}
	public void setUploadContentType(String uploadContentType) {
		this.uploadContentType = uploadContentType;
	}
	public String getUploadFileName() {
		return uploadFileName;
	}
	public void setUploadFileName(String uploadFileName) {
		this.uploadFileName = uploadFileName;
	}
	
}
